<!DOCTYPE html>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script> -->
    <script src="../node_modules/vue/dist/vue.global.js"></script>
    <style>
        input {
            outline: none;
        }
    </style>
</head>

<body>
    <div id="app">
        <input v-tel type="text" v-model='phone' placeholder="请输入手机号">
    </div>
</body>

</html>
<script>
    // 注意: vue 自定义指令中钩子函数的this 指向window, 而不是vm 实例
    const { createApp } = Vue;
    const vm = createApp({
        data() {
            return {
                message1: 'Hello',
                phone: ''
            }
        },
        directives: {
            tel: {
                updated(el, binding) {
                    console.log(el);
                    // console.log('this', this);
                    // console.log(vm);
                    console.log(el.value);
                    if (/^1[3-9]\d{9}$/.test(el.value)) {
                        // 正确
                        el.style.borderColor = 'green'
                    } else {
                        // 错误
                        el.style.borderColor = 'red'
                    }

                }
            }
        },
        methods: {
            fn() {
                return this
            }
        }

    }).mount('#app') 
</script>